/**
 * @author LKQ
 * @date 2022/1/12 16:43
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.backspaceCompare("ab#c", "ad#c");
    }

    public boolean backspaceCompare(String s, String t) {
        return help(s).equals(help(t));
    }
    public String help(String temp) {
        StringBuffer sb = new StringBuffer();
        for (char t : temp.toCharArray()) {
            if (t != '#') {
                sb.append(t);
            }else {
                if (sb.length() > 0) {
                    sb.deleteCharAt(sb.length()-1);
                }
            }
        }
        return sb.toString();
    }
}
